"""
  模块描述：短链接client 调用demo
  @author 8526
  @date 2022-05-13 14:09:25
  版权所有 Copyright www.dahantc.com
"""

import common.util as util
import shorturl.param as param
import shorturl.shorturlapi as api

client = api.ShortUrlClient('http://180.168.192.126:16766')

pwdMd5 = util.md5Encode("456.com")
account = "dhst8526"


# 短链接获取demo
def shortUrlGetDemo():
    shortUrlGetParam = param.ShortUrlGetParam(account, pwdMd5, 'http://www.baidu.com', '4')
    res = client.shortUrlGet(shortUrlGetParam)
    print('短链接获取请求响应', res.__dict__)


# 微信小程序短链接获取demo
def shortUrlGet4AppletDemo():
    shortUrlGetParam = param.ShortUrlGet4WechatAppletParam(account, pwdMd5, 'http://www.baidu.com', '4', 'http://images/222.jpg')
    res = client.shortUrlGet4Applet(shortUrlGetParam)
    print('微信小程序短链接获取请求响应', res.__dict__)

# 短链接发送demo
def shortUrlSendDemo():
    files = {"phonesFile": ("p.zip", open("C:\\temp\\p.zip", "rb"), "application/zip")}
    shortUrlSendParam = param.ShortUrlSendParam(account, pwdMd5, 'https://www.baidu.com', 4, '【大汉三通】',
                                                '测试内容,点击https://www.baidu.com快', None, files)
    res = client.shortUrlSend(shortUrlSendParam)
    print('短链接发送请求响应', res.__dict__)


if __name__ == '__main__':
    shortUrlSendDemo()
    print('--------------------')
    shortUrlGetDemo()
    print('--------------------')
    shortUrlGet4AppletDemo()
